import {
	createApp,
	reactive,
} from 'vue';

import store from './store';
import router from './router';
import App from './App.vue';
import Element from "element-plus";
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import ElementPlus from 'element-plus';
import 'element-plus/theme-chalk/index.css';

Date.prototype.DtFormat = function(fmt) {
	if (!fmt)
		return this.toString();
	var yyyy = this.getFullYear(),
		MM = this.getMonth() + 1, //月
		dd = this.getDate(), //日
		HH = this.getHours(), //24
		hh = this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //12
		mm = this.getMinutes(), //分 
		ss = this.getSeconds(), //秒    
		sss = this.getMilliseconds(), //毫秒    
		wek = this.getDay();
	//dd = dd < 10 ? '0' + dd : dd;
	mm = mm < 10 ? '0' + mm : mm;
	ss = ss < 10 ? '0' + ss : ss;
	HH = HH < 10 ? '0' + HH : HH;
	dd = dd < 10 ? '0' + dd : dd;
	MM = MM < 10 ? '0' + MM : MM;

	var week = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];

	var v = fmt.replace("dddd", week[wek]).replace("yyyy", yyyy).replace("YYYY", yyyy).replace("MM", MM).replace(
		"dd",
		dd);
	v = v.replace("HH", HH).replace("hh", hh).replace("mm", mm).replace("ss", ss);

	return v;
};
Date.prototype.getMW7 = function() {
	let tdate = this;

	let prev = new Date(new Date(tdate).setDate(0)); //上个月最后一天

	let did = prev.getDate();
	let wid = prev.getDay(); //一周7天
	let days = [];
	for (var i = wid; i > 0; i--) {
		days.push(did - i + 1);
		//console.log("day:", did - i+1);
	}
	let tds = new Date(new Date(tdate.setMonth(tdate.getMonth() + 1)).setDate(0)).getDate();
	for (var i = 0; i < tds; i++) {
		days.push(i + 1);
	}
	let next = 7 - days.length % 7;
	for (var i = 0; i < next; i++) {
		days.push(i + 1);
	}
	//console.log(days);
	return days;
}
Date.prototype.getPrev = function() {
	let tdate = this; 
	let prev = new Date(new Date(tdate).setDate(0)); //上个月最后一天

	let did = prev.getDate();
	let wid = prev.getDay(); //一周7天
	let days = [];
	for (var i = wid; i > 0; i--) {
		days.push(did - i + 1);
		//console.log("day:", did - i+1);
	}
	return days;
}
Date.prototype.getNext = function(dcount) {
	let days = [];
	let next = 7 - dcount % 7;
	for (var i = 0; i < next; i++) {
		days.push(i + 1);
	}
	return days;
}

// var oriXOpen = XMLHttpRequest.prototype.open;
// XMLHttpRequest.prototype.open = function(method, url, asncFlag, user, password) {
// 	//code to trace or intercept
// 	 oriXOpen.call(this, method, url, asncFlag, user, password);
// 	if (this.upload) {
// 		let tk = localStorage.getItem("jdtk");
// 		this.setRequestHeader("Authorization", tk);
// 	}
// 	//console.log("拦截",this);
// };

const param = reactive({
	userName: "jd-xiandao",
	password: "jdmap@2012",
});
store.state.user.uinfo = param;
store.dispatch("Login", param);
var app = createApp(App);
app.use(store)
	.use(router)
	.use(Element, {
		locale: zhCn
	});

var vm = app.mount('#app');